<?php

require_once dirname(__FILE__) . '/Dice.php';
require_once dirname(__FILE__) . '/Game.php';
require_once dirname(__FILE__) . '/Board/SpaceMaker.php';
require_once dirname(__FILE__) . '/Board/GroupMaker.php';
require_once dirname(__FILE__) . '/Monopoly/Board.php';
require_once dirname(__FILE__) . '/Player/Piece.php';
require_once dirname(__FILE__) . '/Player.php';

$dice = new Dice('SixSided', 2);

$space_maker = new Board_SpaceMaker();
$group_maker = new Board_GroupMaker();
$board = new Monopoly_Board($space_maker, $group_maker);

/****************************/
echo "Testing Player Movement:\n";

$start_at = 'Go';
echo "\tStarted at $start_at\n";
$piece = new Player_Piece('test', $board->getSpace($start_at));
$player = new Player($piece);

$move = 7;
echo "\tMoved $move spaces\n";
$piece->move($move);

echo "\tEnded at " . $piece->getSpace()->getName() . "\n";

$start_at = 'Boardwalk';
echo "\tStarted at $start_at\n";
$piece = new Player_Piece('test', $board->getSpace($start_at));
$player = new Player($piece);

$move = 6;
echo "\tMoved $move spaces\n";
$piece->move($move);

echo "\tEnded at " . $piece->getSpace()->getName() . "\n";

/****************************/
echo "Testing Game rounds:\n";

$players = array();

$piece = new Player_Piece('horse', $board->getSpace('Go'));
$players[] = new Player($piece);

$piece = new Player_Piece('car', $board->getSpace('Go'));
$players[] = new Player($piece);

$piece = new Player_Piece('snake', $board->getSpace('Go'));
$players[] = new Player($piece);

$piece = new Player_Piece('spoon', $board->getSpace('Go'));
$players[] = new Player($piece);

$piece = new Player_Piece('shoe', $board->getSpace('Go'));
$players[] = new Player($piece);

$piece = new Player_Piece('iron', $board->getSpace('Go'));
$players[] = new Player($piece);

$piece = new Player_Piece('subir', $board->getSpace('Go'));
$players[] = new Player($piece);

$piece = new Player_Piece('can', $board->getSpace('Go'));
$players[] = new Player($piece);

$game = new Game($dice, $board, $players);

// play 20 rounds
for ($i = 0; $i < 20; $i++) {
    $game->playRound();
}

echo "\tGame Rounds:" . $game->getRoundsPlayed() . "\n";

$initial_order = $game->getPlayers();

foreach ($game->getPlayers() as $player) {
    echo "\t" . $player->getPiece()->getName()
        . " Rounds:" . $player->getTurnsPlayed()
        . "\t\t\tat " . $player->getPiece()->getSpace()->getName() . "\n";
}

echo "\tInitial order:\t" . implode(', ', $initial_order) . "\n";
echo "\tFinal order:\t" . implode(', ', $game->getPlayers()) . "\n";

/**********************************/
echo "Testing passing over Go\n";

$piece = new Player_Piece('passGo', $board->getSpace('Boardwalk'));
$player = new Player($piece);

echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$piece->move(2);

echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";

/**********************************/
echo "Testing landing on Go\n";

$piece = new Player_Piece('landGo', $board->getSpace('Boardwalk'));
$player = new Player($piece);

echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$piece->move(1);

echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";

/**********************************/
echo "Testing landing on non-Go\n";

$piece = new Player_Piece('nonGo', $board->getSpace('New York Avenue'));
$player = new Player($piece);

echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$piece->move(3);

echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";

/**********************************/
echo "Testing landing on Go To Jail\n";

$piece = new Player_Piece('landJail', $board->getSpace('Ventnor Avenue'));
$player = new Player($piece);

echo "\tPlayer's starting position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$spaces = 3;
echo "\tPlayer moves $spaces spaces\n";
$piece->move($spaces);

echo "\tPlayer's ending position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";

/*********************************/
echo "Testing landing on Income Tax:\n";

$piece = new Player_Piece('landTax', $board->getSpace('Baltic Avenue'));
$player = new Player($piece);
$player->setBalance(1800);

echo "\tPlayer's starting position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$spaces = 1;
echo "\tPlayer moves $spaces spaces\n";
$piece->move($spaces);

echo "\tPlayer's ending position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";


$piece = new Player_Piece('landTax', $board->getSpace('Baltic Avenue'));
$player = new Player($piece);
$player->setBalance(2200);

echo "\tPlayer's starting position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$spaces = 1;
echo "\tPlayer moves $spaces spaces\n";
$piece->move($spaces);

echo "\tPlayer's ending position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";


$piece = new Player_Piece('landTax', $board->getSpace('Baltic Avenue'));
$player = new Player($piece);
$player->setBalance(2200);

echo "\tPlayer's starting position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$spaces = 1;
echo "\tPlayer moves $spaces spaces\n";
$piece->move($spaces);

echo "\tPlayer's ending position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";


$piece = new Player_Piece('landTax', $board->getSpace('Baltic Avenue'));
$player = new Player($piece);
$player->setBalance(0);

echo "\tPlayer's starting position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$spaces = 1;
echo "\tPlayer moves $spaces spaces\n";
$piece->move($spaces);

echo "\tPlayer's ending position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";


$piece = new Player_Piece('landTax', $board->getSpace('Baltic Avenue'));
$player = new Player($piece);
$player->setBalance(2000);

echo "\tPlayer's starting position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$spaces = 1;
echo "\tPlayer moves $spaces spaces\n";
$piece->move($spaces);

echo "\tPlayer's ending position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";


$piece = new Player_Piece('landTax', $board->getSpace('Baltic Avenue'));
$player = new Player($piece);
$player->setBalance(2000);

echo "\tPlayer's starting position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$spaces = 2;
echo "\tPlayer moves $spaces spaces\n";
$piece->move($spaces);

echo "\tPlayer's ending position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";

/*********************************/
echo "Testing landing on Luxury Tax:\n";

$piece = new Player_Piece('landTax', $board->getSpace('Park Place'));
$player = new Player($piece);
$player->setBalance(100);

echo "\tPlayer's starting position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$spaces = 1;
echo "\tPlayer moves $spaces spaces\n";
$piece->move($spaces);

echo "\tPlayer's ending position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";


$piece = new Player_Piece('landTax', $board->getSpace('Park Place'));
$player = new Player($piece);
$player->setBalance(100);

echo "\tPlayer's starting position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's starting balance: " . $player->getBalance() . "\n";

$spaces = 2;
echo "\tPlayer moves $spaces spaces\n";
$piece->move($spaces);

echo "\tPlayer's ending position: " . $player->getPiece()->getSpace()->getName() . "\n";
echo "\tPlayer's ending balance: " . $player->getBalance() . "\n";
